using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.IO;
using System.Xml.Serialization;
using System.Collections.ObjectModel;

namespace BodySoundSimulator.CaseData
{
    public class AuscultationSiteInfo
    {
        #region Fields
        PointF location;
        Collection<SoundForAuscultationConfiguration> soundsForConfiguration;
        #endregion

        #region Properties
        public PointF Location
        {
            get { return location; }
            set { location = value; }
        }

        [XmlIgnore]
        public Collection<SoundForAuscultationConfiguration> SoundsForConfiguration
        {
            get { return soundsForConfiguration; }
            set { soundsForConfiguration = value; }
        }
        #endregion

        #region Constructors
        public AuscultationSiteInfo()
        {
            this.soundsForConfiguration = new Collection<SoundForAuscultationConfiguration>();
            //add default configuration information
            this.soundsForConfiguration.Add(new SoundForAuscultationConfiguration(AuscultationConfiguration.NormalBreath));
            this.soundsForConfiguration.Add(new SoundForAuscultationConfiguration(AuscultationConfiguration.BreathUp));
            this.soundsForConfiguration.Add(new SoundForAuscultationConfiguration(AuscultationConfiguration.BreathDown));
            this.soundsForConfiguration.Add(new SoundForAuscultationConfiguration(AuscultationConfiguration.RapidBreath));
        }
        #endregion

        #region public methods
        public void Serialize(BinaryWriter writer)
        {
            writer.Write(this.location.X);
            writer.Write(this.location.Y);
            int length = soundsForConfiguration.Count;
            writer.Write(length);
            for (int index = 0; index < length; index++)
            {
                this.soundsForConfiguration[index].Serialize(writer);
            }
        }

        public void Deserialize(BinaryReader reader, float latestVersion)
        {
            reader.ReadSingle();
            this.location = new PointF(reader.ReadSingle(), reader.ReadSingle());
            int length = reader.ReadInt32();
            for (int index = 0; index < length; index++)
            {
                this.soundsForConfiguration[index].Deserialize(reader, latestVersion);
            }
        }
        #endregion
    }
}
